<?
class Tbl_video extends CI_Model {
    var $table;

     function __construct(){
         // Call the Model constructor
         parent::__construct();
		 $this->table ="tbl_video";
     }

	function load_admin(){
	$posisi = $this->uri->segment(3);
    if(!is_numeric($posisi))
    {
      $posisi='0';
      $query=$this->db->query("SELECT * FROM ".$this->table." ORDER BY tanggal DESC LIMIT $posisi,15");
      return $query->result();
    }
	if(empty($posisi)) {$posisi = '0';}
		$query=$this->db->query("SELECT * FROM ".$this->table." ORDER BY tanggal DESC LIMIT $posisi,15");
		return $query->result();
	}
		
	function hitung(){ 
		$data = $this->db->query("SELECT * FROM ".$this->table."");
		$banyak= $this->db->affected_rows($data);
		return $banyak;
	}
		 
	function delete($id){
		$this->db->query("DELETE FROM ".$this->table." WHERE id=$id");
    }
	
	function edit($id) {
      $query=$this->db->query("SELECT * FROM ".$this->table." WHERE id='$id'");
      return $query->result();
	 }
	
	function add($nama_video, $url_file, $tanggal,$deskripsi){
		$this->db->query("INSERT INTO ".$this->table." SET
							id    		 = 'null',
							nama_video   = '$nama_video',
							url			 = '$url_file',
							tanggal		 = '$tanggal',
							deskripsi  	 = '$deskripsi'");
	}
	
	function update($id, $nama_video, $url_file, $tanggal,$deskripsi){
		$this->db->query("UPDATE ".$this->table." SET
							nama_video   = '$nama_video',
							url			 = '$url_file',
							tanggal		 = '$tanggal',
							deskripsi  	 = '$deskripsi' WHERE id='$id'");
	}
	
	function getLatestVideo(){
		$query = $this->db->query("SELECT * FROM ".$this->table." ORDER BY tanggal DESC");
		return $query->row();
	}
	
	function LoadGuestVideo(){
		$query = $this->db->query("SELECT * FROM ".$this->table." ORDER BY tanggal DESC");
		return $query->result();
	}
	
	function searchVideoGuest($key){
		$query = $this->db->query("SELECT * FROM ".$this->table." WHERE nama_video RLIKE '%$key%' OR deskripsi RLIKE '%$key%'");
		return $query->result();
	}
	
	function load_guest(){
	$posisi = $this->uri->segment(3);
    if(!is_numeric($posisi))
    {
      $posisi='0';
      $query=$this->db->query("SELECT * FROM ".$this->table." ORDER BY tanggal DESC LIMIT $posisi,3");
      return $query->result();
    }
	if(empty($posisi)) {$posisi = '0';}
		$query=$this->db->query("SELECT * FROM ".$this->table." ORDER BY tanggal DESC LIMIT $posisi,3");
		return $query->result();
	}
	
}
?>